﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using System.ComponentModel.Composition;

using org.theGecko.Utilities.MefMvc;

using LeMigue.Scrum.Iterface.Model;

using LeMigue.TeamPortal.Base.Mvc;
using LeMigue.TeamPortal.Base.View;

using LeMigue.Scrum.Iterface.Service;
using LeMigue.Scrum.TfsScrumV1.Service;
using LeMigue.TeamPortal.Base.Biz.Interface;
using LeMigue.TeamPortal.Base.Biz.Implement;
using LeMigue.TeamPortal.Base.Biz;


namespace LeMigue.TeamPortal.Sprint.Controllers
{
    /*[HandleError]*/
    [ControllerMetaData("Sprint")]
    [Export(typeof(IController)), PartCreationPolicy(CreationPolicy.NonShared)]
    [Authorize]
    [CheckTeam]
    public class SprintController : TeamPortalController
    {

        private Iteration interacaoSelecionada = null;

        private ISprintBiz SprintBiz = FactoryBiz.SprintBiz;
        private IIterationBiz IterationBiz = FactoryBiz.IterationBiz;

        public ActionResult Index()
        {
            
            return View();
        }

        [ContainerHome("Sprint", 1)]
        public PartialViewResult HomeBox()
        {
            return PartialView();
        }

        //TODO: ver no mef como registrar esta chamada por outros plugins e não dar erro caso não tenha
        [ChildActionOnly]
        public PartialViewResult TreeIteration(IterationView interacao, IterationView selecionada = null)
        {
            if (interacaoSelecionada == null && selecionada != null)
                interacaoSelecionada = selecionada.Iteration;

            IList<IterationView> interacoes = new List<IterationView>();

            if (interacao.Iteration == null)
            {
                interacoes = IterationBiz.List(Team, interacaoSelecionada);

                if (interacoes.Count <= 0)
                    return PartialView("NoIteration");
            }
            else
            {
                interacoes = IterationBiz.List(interacao.Iteration.Child, interacaoSelecionada);
                if (interacoes.Count <= 0)
                    return PartialView("Empty");
            }

            return PartialView(interacoes);
        }

    }
}
